package com.qf.job;

import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 分布式任务调度 :
 *      自定义业务中执行的任务内容
 * @author zhaojian
 */
@Component
public class MyJob implements SimpleJob {

    /**
     * 定时任务 执行的内容
     * @param context
     */
    @Override
    public void execute(ShardingContext context) {
        //获取当前要执行任务的  分片
        int shardingItem = context.getShardingItem();
        //分片： 0  1  2  叫3个分片
        switch (shardingItem) {
            case 0:
                // do something by sharding item 0
                System.out.println("000000000000000" + new Date());
                break;
            case 1:
                // do something by sharding item 1
                System.out.println("111111111111111" + new Date());
                break;
            case 2:
                // do something by sharding item 2
                System.out.println("222222222222222" + new Date());
                break;
            // case n: ...
        }
    }
}